﻿using System.Collections.Generic;
using System.Linq;

namespace Sidvall.Data
{
    public class BusinessRuleFilter
    {
        #region Public Members

        public BusinessRuleFilterType FilterType { get; set; }
        public bool IncludeNotBrokenRules { get; set; }
        #region Categories

        private System.Lazy<NameCollection> _Categories = new System.Lazy<NameCollection>();
        public NameCollection Categories
        {
            get
            {
                return _Categories.Value;
            }
        }

        #endregion
        #region Severities

        private System.Lazy<RuleSeverityCollection> _Severities = new System.Lazy<RuleSeverityCollection>();
        public RuleSeverityCollection Severities
        {
            get
            {
                return _Severities.Value;
            }
        }

        #endregion

        #region CreateFilter

        public static BusinessRuleFilter CreateFilter()
        {
            return new BusinessRuleFilter();
        }
        public static BusinessRuleFilter CreateFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, params string[] categories)
        {
            return CreateFilter(type, includeNotBrokenRules, categories.AsEnumerable());
        }
        public static BusinessRuleFilter CreateFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, IEnumerable<string> categories)
        {
            return new BusinessRuleFilter(type, includeNotBrokenRules, categories);
        }
        public static BusinessRuleFilter CreateFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, params RuleSeverity[] severities)
        {
            return CreateFilter(type, includeNotBrokenRules, severities.AsEnumerable());
        }
        public static BusinessRuleFilter CreateFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, IEnumerable<RuleSeverity> severities)
        {
            return new BusinessRuleFilter(type, includeNotBrokenRules, severities);
        }

        #endregion

        #endregion
        #region Constructors

        public BusinessRuleFilter()
        {
            this.FilterType = BusinessRuleFilterType.HasRuleSeverity;
            this.IncludeNotBrokenRules = false;
            this.Severities.Add(RuleSeverity.Error);
        }
        public BusinessRuleFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, IEnumerable<string> categories)
        {
            this.FilterType = type;
            this.IncludeNotBrokenRules = includeNotBrokenRules;
            this.Categories.AddRange(categories);
        }
        public BusinessRuleFilter(BusinessRuleFilterType type, bool includeNotBrokenRules, IEnumerable<RuleSeverity> severities)
        {
            this.FilterType = type;
            this.IncludeNotBrokenRules = includeNotBrokenRules;
            this.Severities.AddRange(severities);
        }

        #endregion
    }
}
